<?php

/*
 A very simple syslog MA that provides access to entries in the syslog file
 in 5 minute intervals. This MA is part of the tutorial on how to implement
 your own MAs
 */

require_once("ma.abs.php");

class snmpma1 extends MA {

	var $data;

	function getName()
	{
		return "192.168.1.1_snmp";
	}

    function getTableorSingleData($source,$timeperiods,$report,$obspoints,$type,$view,$filter,$sort,$rowlimit,$arguments)
    {
            $ret=array();
            $count=0;
            foreach($timeperiods as $tp) 
            {
                    $ret[$tp['resolution']][$tp['timestamp']][1]=array();
                    $interfaceStats=fopen("/home/madave/Documents/perfSONARNC/snmpma1/testSyslog.db","r");
                    while($str=fgets($interfaceStats)) 
                    {
                            $time = $this->getTime($str);
                            preg_match("/:.*/",$str,$m);    
                            if($rowlimit==0 or $rowlimit>$count++)
                                    $ret[$tp['resolution']][$tp['timestamp']][1][]=array($time,$m[0]);
                    }
                    fclose($interfaceStats);
            }
            return $ret;
    }

	function getDatasources()
	{
		return array('192.168.1.1_snmp'=>"192.168.1.1_snmp");
	}

	function getObspoints($source)
	{
		return array(array('id'=>1,
			   'name'=>"localhost"));
	}


    function getTimeInfo($source)
    {
            $first=$this->getTime(`head /home/madave/Documents/perfSONARNC/snmpma1/testSyslog.db -n 1`);
            $last=$this->getTime(`tail /home/madave/Documents/perfSONARNC/snmpma1/testSyslog.db|tail -n 1`);                       
                    
            $ret=array();
            $ret[]=array('id'=>1,
                                    'name'=>"5 min",
                                    'duration'=>300,
                                    'plot_from'=>"",
                                    'first'=>$first,
                                    'last'=>$last);
            $ret[]=array('id'=>2,
                                    'name'=>"Hour",
                                    'duration'=>3600,
                                    'plot_from'=>1,
                                    'first'=>$first,
                                    'last'=>$last);
            return $ret;
    }

    private function getTime($str)
    {
            preg_match("/.*:/", $str, $result);
            return $result[0];
    }

}
?>
